DataOutputAgent: Use `template.self` as URL for the feed itself

This is useful when you serve a feed generated by DataOutputAgent via
reverse proxy.

Akinori MUSHA 9 years ago
parent
commit
c03a60ec48
1 changed files with 7 additions and 6 deletions
  1. 7 6
      app/models/agents/data_output_agent.rb

+ 7 - 6
app/models/agents/data_output_agent.rb

@@ -19,7 +19,7 @@ module Agents
19 19
 
20 20
           * `secrets` - An array of tokens that the requestor must provide for light-weight authentication.
21 21
           * `expected_receive_period_in_days` - How often you expect data to be received by this Agent from other Agents.
22
-          * `template` - A JSON object representing a mapping between item output keys and incoming event values.  Use [Liquid](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid) to format the values.  Values of the `link`, `title`, `description` and `icon` keys will be put into the \\<channel\\> section of RSS output.  The `item` key will be repeated for every Event.  The `pubDate` key for each item will have the creation time of the Event unless given.
22
+          * `template` - A JSON object representing a mapping between item output keys and incoming event values.  Use [Liquid](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid) to format the values.  Values of the `link`, `title`, `description` and `icon` keys will be put into the \\<channel\\> section of RSS output.  Value of the `self` key will be used as URL for this feed itself, which is useful when you serve it via reverse proxy.  The `item` key will be repeated for every Event.  The `pubDate` key for each item will have the creation time of the Event unless given.
23 23
           * `events_to_show` - The number of events to output in RSS or JSON. (default: `40`)
24 24
           * `ttl` - A value for the \\<ttl\\> element in RSS output. (default: `60`)
25 25
 
@@ -114,11 +114,12 @@ module Agents
114 114
     end
115 115
 
116 116
     def feed_url(options = {})
117
-      feed_link + Rails.application.routes.url_helpers.
118
-                  web_requests_path(agent_id: id || ':id',
119
-                                    user_id: user_id,
120
-                                    secret: options[:secret],
121
-                                    format: options[:format])
117
+      interpolated['template']['self'].presence ||
118
+        feed_link + Rails.application.routes.url_helpers.
119
+                    web_requests_path(agent_id: id || ':id',
120
+                                      user_id: user_id,
121
+                                      secret: options[:secret],
122
+                                      format: options[:format])
122 123
     end
123 124
 
124 125
     def feed_icon